//
//  erveyAreaViewController.m
//  INAlienLand
//
//  Created by dllo on 15/7/1.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "erveyAreaViewController.h"
#import "destinationInterfaceViewController.h"
#import "HTTPTool.h"
#import "DestCollectionViewCell.h"
#import "destCollectionHeaderReusableView.h"
#import "arerModel.h"
#import "UIImageView+WebCache.h"
#import "dataInArr.h"
#import "placeDetail.h"
#import "placeDetailTableViewCell.h"
#import "MapViewController.h"
#import "imageViewController.h"
#import "cityCollectionReusableView.h"
#import "HimageCollectionViewCell.h"


#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface erveyAreaViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>

//创建页面的collect
@property (nonatomic,retain)UICollectionView *cityCollectView;

@property (nonatomic,copy)NSString *str;
@property (nonatomic,retain)UIImageView *headerImage;
@property (nonatomic,retain)UILabel *lableName;
@property (nonatomic,retain)UILabel *lableRate;
@property (nonatomic,retain)UILabel *lableItro;
@property (nonatomic,retain)NSMutableArray *placeDetailArr;
@property (nonatomic,retain)UIImageView *imageView;
@property (nonatomic,assign)BOOL isLike;
@end

@implementation erveyAreaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createData];
    [self createCollect];
}
-(void)createData
{
    [HTTPTool get:[NSString stringWithFormat:@"http://api.breadtrip.com/destination/place/%@/%@/",self.arer.type,self.arer.bId] body:nil HTTPResult:JSON success:^(id result) {
        NSDictionary *Dic = result;
        
        self.placeDetailArr = [NSMutableArray array];
        [self.placeDetailArr addObject:@"1"];
        NSDictionary *inDic = Dic[@"share_args"];
        NSDictionary *qqDic = inDic[@"default"];
        self.str = qqDic[@"shr_image"];
        NSLog(@"11");
        
        [self.cityCollectView reloadData];
    } failure:^(NSError *error) {
        
    }];

}
-(void)createCollect
{
    UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc]init];
    flowlayout.itemSize = CGSizeMake((WIDTH-50)/2, (WIDTH-50)/2);
    flowlayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    self.cityCollectView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) collectionViewLayout:flowlayout];
    [self.view addSubview:self.cityCollectView];
    self.cityCollectView.delegate = self;
    self.cityCollectView.dataSource = self;
    [self.cityCollectView registerClass:[HimageCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    flowlayout.headerReferenceSize = CGSizeMake(WIDTH, HEIGHT / 2);
    [self.cityCollectView registerClass:[cityCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
    
}

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    cityCollectionReusableView *head = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:indexPath];
   // NSLog(@"%@",self.str);
    [head.bigImage sd_setImageWithURL:[NSURL URLWithString:self.str]];
    //layer负责显示控件中的一些设置信息,比如边框,弧度等
    //创建一个动画的效果
    CATransition *transistio = [CATransition animation];
    //设置动画的类型
    transistio.type = @"oglFlip";
    
    //    suckEffect（三角）
    //
    //    rippleEffect（水波抖动）
    //
    //    pageCurl（上翻页）
    //
    //    pageUnCurl（下翻页）
    //
    //    oglFlip（上下翻转）
    
    //设置动画的时长
    
    [transistio setDuration:3];
    //设置动画的重复次数
    [transistio setRepeatCount:1];
    
    //向imageview的layer里添加动画效果
    [head.bigImage.layer addAnimation:transistio forKey:@"rippleEffect"];
    

    head.backgroundColor = [UIColor whiteColor];
    //imageview添加点击手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [head addGestureRecognizer:tap];
    head.userInteractionEnabled = YES;
    return head;
}
-(void)tapAction:(UIGestureRecognizer *)tap
{
    imageViewController *imageview =[[imageViewController alloc]init];
    [self.navigationController pushViewController:imageview animated:YES];
    imageview.arer = self.arer;
    NSLog(@"%@",imageview.arer.type);
    
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.placeDetailArr.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HimageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
